/**
 * 
 */
package com.base.myproject.client.busi.b2c;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.BaseStoreEvent.EventType;
import com.base.myproject.client.busi.b2c.b2cgcodeattr.AttrFactory;
import com.base.myproject.client.jdbc.StoreInfo;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.Html;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;

/**
 * 自动翻页效果，结合jquery  运行
 * base.js 里面定义了运行办法
 * @author zgw
 *2009-8-6 下午12:43:32
 * javazgw@gmail.com
 */
public class AutoDisplay {
	BaseStore<BaseModelData> imagestore;
	static String str = "";
	public AutoDisplay()
	{
		init();
		
	}

	void init()
	{
		CreateImageStore();
	}
	
	void CreateImageStore() {

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("b2cgcode");
		type.addField("description");
		type.addField("imagepath");
		type.addField("gcode");
	

		StoreInfo info = new StoreInfo();
		info.setTablename("b2cgcodeautodisplay");
		info.setSql("select b2cgcode,description,imagepath,gcode from b2cgcodeautodisplay");

		imagestore = new BaseStore<BaseModelData>(type, info);
		imagestore.setName("b2cgcodeautodisplay");

		
	}
	public Widget Display()
	{
		final Html h = new Html();
		
		imagestore.addBaseStoreListener(EventType.LOAD_COMPLETE,
				new BaseStoreListener() {

					@Override
					public void BaseStoreEventHandle(BaseStoreEvent evt) {
						// TODO Auto-generated method stub
						str="            ";
						/*str+="<div id=\"TBplayer\">             ";
						str+="	<ul>                   ";
						String link = "";
						for(int i=0;i<imagestore.getCount();i++)
						{
						//str+="   asdfjasljdfljasdflj;lzlgjwljel ";
						str+="		<li>    ";
						str+="			<div class=\"left\">      ";
				
						str+="				<p class=\"pres\">      ";
						str+=imagestore.getValue(i, "description");
					   
						str+="				</p>                    ";
						str+="			</div>                    ";
						str += "			<div class=\"right\"><img src=\""+imagestore.getValue(i, "imagepath")+"\" alt=\"\" /></div> ";
						str+="			<div class=\"clearfix\"></div>                  ";
						str+="		</li>  ";
						if(i==0)
						{
							link+="		<span><a href=\"javascript:void(0)\" class=\"active\">"+(i+1)+"</a></span>  ";
						}
						else
						{
							link+="		<span><a href=\"javascript:void(0)\" >"+(i+1)+"</a></span>  ";
						}
						}
						str+="	</ul>   ";
						str+="	<div id=\"TBnav\">            ";

						str+=link;
						str+="	</div>  ";
						str+="</div>       ";*/
						bb();
						str +=aa(imagestore) ;
					//	System.out.println("str=="+str);
						h.setHtml(str);
						
						execjavascript();
					}

					@Override
					public void onBrowserEvent(Event event) {
						// TODO Auto-generated method stub
						
					}

		});
	/*	
		str+="            ";
		str+="<div id=\"TBplayer\">             ";
		str+="	<ul>      ";
		str+="		<li>    ";
		str+="			<div class=\"left\">      ";
		str+="				<h2>11111111111</h2>    ";
		str+="				<p class=\"pres\">      ";
		str+="					jobberBase is a great solution for<br />    ";
		str+="					single-industry recruitment.<br /><br />    ";
		str+="					Keep it simple and keep it focused!         ";
		str+="				</p>                    ";
		str+="			</div>                    ";
		str+="			<div class=\"right\"><img src=\"images/slide1.jpg\" alt=\"\" /></div> ";
		str+="			<div class=\"clearfix\"></div>                  ";
		str+="		</li> ";
		str+="		<li>  ";
		str+="			<div class=\"left\">      ";
		str+="				<h2>22222222222</h2>    ";
		str+="				<p class=\"pres\">      ";
		str+="					jobberBase is a great solution for<br />    ";
		str+="					single-industry recruitment.<br /><br />    ";
		str+="					Keep it simple and keep it focused!         ";
		str+="				</p>                    ";
		str+="			</div>                    ";
		str+="			<div class=\"right\"><img src=\"images/slide1.jpg\" alt=\"\" /></div> ";
		str+="			<div class=\"clearfix\"></div>                  ";
		str+="		</li> ";
		str+="		<li>  ";
		str+="			<div class=\"left\">      ";
		str+="				<h2>333333333333</h2>   ";
		str+="				<p class=\"pres\">      ";
		str+="					jobberBase is a great solution for<br />    ";
		str+="					single-industry recruitment.<br /><br />    ";
		str+="					Keep it simple and keep it focused!         ";
		str+="				</p>                    ";
		str+="			</div>                    ";
		str+="			<div class=\"right\"><img src=\"images/slide1.jpg\" alt=\"\" /></div> ";
		str+="			<div class=\"clearfix\"></div>                  ";
		str+="		</li> ";
		str+="		<li>  ";
		str+="			<div class=\"left\">      ";
		str+="				<h2>444444444</h2>      ";
		str+="				<p class=\"pres\">      ";
		str+="					jobberBase is a great solution for<br />    ";
		str+="					single-industry recruitment.<br /><br />    ";
		str+="					Keep it simple and keep it focused!         ";
		str+="				</p>                    ";
		str+="			</div>                    ";
		str+="			<div class=\"right\"><img src=\"busiimages/20090714/1247575415421m (1).jpg\" alt=\"\" /></div> ";
		str+="			<div class=\"clearfix\"></div>                  ";
		str+="		</li> ";
		str+="	</ul>   ";
		str+="	<div id=\"TBnav\">            ";
		str+="		<span><a href=\"javascript:void(0)\" class=\"active\">111111111</a></span>                    ";
		str+="		<span><a href=\"javascript:void(0)\">2222</a></span>                    ";
		str+="		<span><a href=\"javascript:void(0)\">3333</a></span>                    ";
		str+="		<span><a href=\"javascript:void(0)\">44444</a></span>                   ";
		str+="	</div>  ";
		str+="</div>    ";
//		str+="<div id=\"TBc\">                ";
//		str+="		<span><a href=\"javascript::void(0)\" onclick=\"javascript:$('#TBplayer').Next({prevId:'TBprev',nextId:'TBnext',bindId:'TBnav',linkId:'TBnav'});\" ; id=\"TBprev\">上一页</a>&nbsp;<a href=\"javascript:void(0)\" id=\"TBnext\">下一页</a></sp";
//		str+="	</div>      ";
		
		h.setHtml(str);
		h.addWidgetListener(new WidgetListener(){
			
			  public void widgetResized(ComponentEvent ce) {
				  System.out.println("widgetResized");
			  }

			  *//**
			   * Fires after a widget is attached.
			   * 
			   * @param ce an event containing information about the event
			   *//*
			  public void widgetAttached(ComponentEvent ce) {
				  System.out.println("widgetAttached");
				  execjavascript();
			  }

			  *//**
			   * Fires after a widget is detached.
			   * 
			   * @param ce an event containing information about the event
			   *//*
			  public void widgetDetached(ComponentEvent ce) {
				  System.out.println("widgetDetached");
			  }
			
		});*/
		
		return h;
	}
	public native void execjavascript() /*-{
		
		$wnd.$('#TBplayer').Next({prevId:'TBprev',nextId:'TBnext',bindId:'TBnav',linkId:'TBnav'});
		
	}-*/;
	
	public native String aa(BaseStore<BaseModelData> imagestore) /*-{
		//$wnd.alert('z1111111111');
		//	getValue(i, "imagepath")
		//$wnd.alert(imagestore.@com.base.myproject.client.busi.BaseStore::getValue(ILjava/lang/String;)(0,'imagepath'));
		var imagepaht = imagestore.@com.base.myproject.client.busi.BaseStore::getValue(ILjava/lang/String;)(0,'imagepath');
		//var test = @com.base.myproject.client.busi.b2c.AutoDisplay::getlink(Ljava/lang/String;)('001');
		//alert(test);
	//	var str = "<a href='javascript:void(0)' onclick=\"javascript: function(){"+@com.base.myproject.client.busi.b2c.AutoDisplay::getlink(Ljava/lang/String;)('001')+"}\">eee</a>";
		//var str = "<a href='javascript:void(0)' onclick=\"javascript: setautodisplaytocenter('20000002')\">eee</a>";
		//var str = "<a href='javascript:void(0)' onclick=\"javascript: function(){"+@com.base.myproject.client.busi.b2c.AutoDisplay::cc()()+"}\">eee</a>";
		var str = "";
		str+="<div id='TBplayer'>";
		str+="<ul>";
		var link = "";
		for( i=0;i<imagestore.@com.base.myproject.client.busi.BaseStore::getCount()();i++)
			{
			
			str+="		<li>    ";
			str+="			<div class=\"left\">      ";

			str+="				<p class=\"pres\">      ";
			str+=imagestore.@com.base.myproject.client.busi.BaseStore::getValue(ILjava/lang/String;)(i, "description");

							str+="				</p>                    ";
							str+="			</div>                    ";
							var id =imagestore.@com.base.myproject.client.busi.BaseStore::getValue(ILjava/lang/String;)(i, "b2cgcode");
						
							//str += "			<div class=\"right\"><img src=\""+imagestore.@com.base.myproject.client.busi.BaseStore::getValue(ILjava/lang/String;)(i, "imagepath")+"\" alt=\"\" /></div> ";
str += "			<div class=\"right\"><a href='javascript:void(0)' onclick=\"javascript: setautodisplaytocenter('"+id+"')\"> <img src=\""+imagestore.@com.base.myproject.client.busi.BaseStore::getValue(ILjava/lang/String;)(i, "imagepath")+"\" alt=\"\" /></a></div> ";

							str+="			<div class=\"clearfix\"></div>                  ";
							str+="		</li>  ";
							if(i==0)
							{
								link+="		<span><a href=\"javascript:void(0)\" class=\"active\">"+(i+1)+"</a></span>  ";
							}
							else
							{
								link+="		<span><a href=\"javascript:void(0)\" >"+(i+1)+"</a></span>  ";
							}
							}
							str+="	</ul>   ";
							str+="	<div id=\"TBnav\">            ";

							str+=link;
							str+="	</div>  ";
							str+="</div>       ";
							
		return str;
		//$wnd.alert('z2222222222');
	}-*/;
	public static native void bb() /*-{
		$wnd.setautodisplaytocenter = function(id){
		
			
			@com.base.myproject.client.busi.b2c.AutoDisplay::getlink(Ljava/lang/String;)(id);
		
		}
		
	}-*/;
	/**
	 * 显示连接到中间窗口
	 * @param id
	 */
	public static void getlink(String id)
	{
	
		AttrFactory af = new AttrFactory(id);
		af.initAttrShow();
		OneProduct oneproduct = new OneProduct(af.getP());
		MainPage.getCenterpanel().removeAll();

		MainPage.getCenterpanel().add(oneproduct);


		MainPage.getCenterpanel().layout();
		
	}
}

